#include <iostream>
#include "AbstractTask.h"
#include "StandardThread.h"
#include "TaskPool.h"

StandardThread::StandardThread(std::shared_ptr<TaskPool> tasks)
    : m_tasks(tasks)
    , m_stopping(true)
{
}

StandardThread::~StandardThread()
{

}

void StandardThread::start()
{
    m_stopping = false;
    m_thread = std::make_shared<std::thread>(&StandardThread::run, this);
    m_thread->detach();
}

void StandardThread::run()
{
    while (!m_stopping)
    {
        std::shared_ptr<AbstractTask> task = m_tasks->takeFirst();
        task->execute();
    }
}


